package com.hqj.consumer.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestConfig {

    @Bean  //通过RestTemplate来实现调用接口
    @LoadBalanced  //RestTemplate开启负载均衡
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }

    @Bean
    public IRule getIRule(){//通过返回一个新的IRule对象，更改负载均衡的策略
        return new RandomRule();//随机数的方式负载均衡
    }


}
